package com.yzy.soft.system.freemarker.template;

import com.yzy.soft.system.freemarker.*;
import com.yzy.soft.system.freemarker.database.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class TemplateServiceImpl extends TemplateKernel {

    private final static Logger logger=LoggerFactory.getLogger(TemplateServiceImpl.class);

    @Override
    public File generateFileType(FileInfo fileInfo,Table table, DBInfo dbInfo) throws Exception {
        JavaFileServiceImpl javaFile=((JavaFile)fileInfo).getJavaFileServiceImpl();
        final String suffix = "ServiceImpl.java";
        String tableName = javaFile.getFilename();
        final String path = fileInfo.getDiskPath() + tableName + javaFile.getSuffix();
        final String templateName = "ServiceImpl.ftl";
        File mapperFile = new File(path);
        logger.info("TemplateServiceImpl path:"+path);
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("package_name", javaFile.getPackageName());
        dataMap.put("table_name", tableName);
        dataMap.put("table_annotation", " ");
        generateFileByTemplate(templateName, mapperFile,fileInfo, dataMap);
        return mapperFile;
    }
}
